return "TYPEWRITER EFFECT" & RETURN & RETURN & "A field or text sprite with this behavior attached displays as if it was being typed onto the screen. " & "To use, place a field or text cast member in place on the stage; and type in the message you want to appear; then attach this behavior. " & "The type can begin to display automatically in the first frame the sprite appears in, or it can be set to wait for an mActive message. " & "You can set the amount of time to wait between characters, and play a sound for each letter." & RETURN & RETURN & "PARAMETERS:" & RETURN & " - Autotype when sprite appears" & RETURN & " - Time between characters" & RETURN & " - Sound to play when character appears" & RETURN & " - Sound channel to use" & RETURN & RETURN & "PERMITTED TYPES:" & RETURN & " - Text or Fields"
end
on getBehaviorTooltip me
return "Types text onto screen into 'visible' or 'invisible' text field. " & "An accompanying sound can be assigned to play as text appears."
end
on beginSprite me
mInitialize(me)
end
on endSprite me
pMember.text = pText
end
on prepareFrame me
mType(me)
end
on mInitialize me
pSprite = sprite(me.spriteNum)
pMember = pSprite.member
pMember.boxType = #fixed
pText = pMember.text
pChars = pText.length
if pChars < 1 then
vError = mErrorAlert(me, #noText)
end if
pMember.text = " "
pIndex = 0
pPeriod = integer(pPeriodBase * 1000)
pStartTime = the milliSeconds - pPeriod
if pSoundChannel then
vError = 0
if pSound = #none then
vError = 1
else
if member(pSound).type <> #sound then
vError = 1
end if
end if
if vError then
pSoundChannel = 0
vError = mErrorAlert(me, #noSound)
end if
end if
end
on mType me
if pActive then
if pIndex >= pChars then
pActive = 0
else
vMillis = the milliSeconds
if (vMillis - pStartTime) > pPeriod then
pIndex = pIndex + 1
if pIndex = 1 then
pMember.text = pText.char[1]
else
pMember.text = pMember.text & pText.char[pIndex]
end if
if pSoundChannel then
puppetSound(pSoundChannel, 0)
puppetSound(pSoundChannel, pSound)
end if
pStartTime = the milliSeconds
end if
end if
end if
end
on mErrorAlert me, vError, vData
vBehaviorname = string(me)
delete word 1 of vBehaviorname
delete char -30001 of vBehaviorname
delete char -30001 of vBehaviorname
case vData.ilk of
#void:
vData = "<void>"
#symbol:
vData = "#" & vData
end case
case vError of
#noText:
alert("CANCEL: Sprite MUST contain formatted text to display correctly")
#noSound:
alert("CANCEL: Sound channel should be set to 0 if no sound is selected")